<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Products extends CI_Controller
{
	public function Index()
	{
		$this->viewDVDs();
	}
	
	public function dvds()
	{
		$this->viewDVDs();
	}
	
	public function viewDVDs()
	{
		$this->load->library(array('pagination', 'table', 'cart'));
		
		$data['query'] = $query = $this->db->get('dvds');
		
		$config['base_url'] = base_url().'products/dvds/?';
		$config['total_rows'] = $query->num_rows;
		$config['per_page'] = 2;
		$config['page_query_string'] = true;
		$config['num_links'] = 5;
		$config['use_page_numbers'] = false;
		
		$this->pagination->initialize($config);
		
		$data['pagination']['start'] = (int) $this->input->get('per_page') ?: 0;
		$data['pagination']['length'] = $config['per_page'];
		if($data['pagination']['start'] < 0)
		{
			$data['pagination']['start'] = 0;
		}
		if($data['pagination']['start'] >= $query->num_rows)
		{
			$data['pagination']['start'] = $query->num_rows - 1;
		}
		
		$this->load->model('UserModel');
		
		$this->load->view("templates/header");
		$this->load->view("templates/sidebars", array('logged_in' => $this->UserModel->isLoggedIn(), 'cart' => $this->cart->contents()));
		$this->load->view("products", $data);
		
		$this->load->view("templates/footer");
	}
}